package com.cst.intercepterdemo.chain.node;

import com.cst.intercepterdemo.context.IInterceptContext;

/**
 * <ul>
 * <li>文件名称 : com.cst.intercepterdemo.chain.node.OrChainNode
 * </li>
 * <li>版权所有 : 版权所有(C)2016-2020</li>
 * <li>公 司 : CST</li>
 * <li>创建时间 : 2016/12/2</li>
 * <li>修改记录 : </li>
 * </ul>
 * 类说明：
 *
 * @author Allen
 * @version 1.0
 */
public class OrChainNode extends AbstractIntercepterChainNode {

    private IIntercepterChainNode[] includeNodes;

    public OrChainNode(IIntercepterChainNode[] includeNodes) {
        if(includeNodes==null || includeNodes.length==0){
            throw new RuntimeException();
        }
        this.includeNodes = includeNodes;
    }
    public OrChainNode(IIntercepterChainNode next,
                        IIntercepterChainNode[] includeNodes) {
        super(next);
        if(includeNodes==null || includeNodes.length==0){
            throw new RuntimeException();
        }
        this.includeNodes = includeNodes;
    }

    @Override
    public boolean intercept(IInterceptContext context) {
        for (IIntercepterChainNode includeNode : includeNodes) {
            if(includeNode.dochain(context)){
                return true;
            }
        }
        return false;
    }
}
